﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VisualPoint.Controls.Models;

namespace VisualPoint.Controls.Actions
{
    public class FileCloseAction : BaseAction
    {

        public override string Name
        {
            get 
            {
                return "Close File";
            }
        }

        public override string Description
        {
            get 
            {
                if (CloseOption == FileCloseOption.ActiveDocument)
                {
                    return "Active Document";
                }
                else if (CloseOption == FileCloseOption.AllDocuments)
                {
                    return "All Document";
                }
                return string.Format("{0} {1} {2}", Project, Folder, FileName);
            }
        }

        public override string Help
        {
            get 
            {
                return "Closes a the editor window of a File";
            }
        }

        public override BaseActionModel CreateModel()
        {
            return new FileCloseActionModel() { Action = this };
        }


        private FileCloseOption _CloseOption;
        public FileCloseOption CloseOption
        {
            get
            {
                return _CloseOption;
            }
            set
            {
                if (_CloseOption != value)
                {
                    _CloseOption = value;
                    DoPropertyChanged("CloseOption");
                    DoDescriptionChanged();
                }
            }
        }

        private string _project;
        public string Project 
        {
            get
            {
                return _project;
            }
            set
            {
                if (_project != value)
                {
                    _project = value;
                    DoPropertyChanged("Project");
                    DoDescriptionChanged();
                }
            }
        }

        private string _fileName;
        public string FileName
        {
            get
            {
                return _fileName;
            }
            set
            {
                if (_fileName != value)
                {
                    _fileName = value;
                    DoPropertyChanged("FileName");
                    DoDescriptionChanged();
                }
            }
        }

        private string _folder;
        public string Folder
        {
            get
            {
                return _folder;
            }
            set
            {
                if (_folder != value)
                {
                    _folder = value;
                    DoPropertyChanged("Folder");
                    DoDescriptionChanged();
                }
            }
        }

        public override void Run()
        {
            VisualPoint.Controls.Environments.Environment.Current.CloseDocument(Project, Folder, FileName, CloseOption);
        }
    }
}
